from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay
import matplotlib.pyplot as plt

# 假设你有以下真实标签和模型预测结果
y_true = [0, 1, 2, 2, 0, 1, 2, 0, 2, 3]
y_pred = [0, 0, 2, 2, 0, 0, 1, 2, 2, 0]


# 生成混淆矩阵
cm = confusion_matrix(y_true, y_pred)

# 可视化混淆矩阵
disp = ConfusionMatrixDisplay(confusion_matrix=cm)
disp.plot()
plt.show()
